<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>CSS规范 | 聚名前端团队文档库</title>
    <meta name="generator" content="VuePress 1.9.5">
    <link rel="icon" href="/jm-team/img/juming_ico.ico">
    <script async="async" src="/jm-team/js/jquery/3.6.0/jquery.min.js"></script>
    <meta name="description" content="聚名前端团队文档库">
    <meta name="keywords" content="聚名前端组组件文档库">
    <meta name="theme-color" content="#11a8cd">
    
    <link rel="preload" href="/jm-team/assets/css/0.styles.e434bceb.css" as="style"><link rel="preload" href="/jm-team/assets/js/app.99b82987.js" as="script"><link rel="preload" href="/jm-team/assets/js/5.d18fc731.js" as="script"><link rel="preload" href="/jm-team/assets/js/6.c8a66f32.js" as="script"><link rel="preload" href="/jm-team/assets/js/37.c0a8f76a.js" as="script"><link rel="prefetch" href="/jm-team/assets/js/1.c6f2da47.js"><link rel="prefetch" href="/jm-team/assets/js/10.59953132.js"><link rel="prefetch" href="/jm-team/assets/js/11.53202447.js"><link rel="prefetch" href="/jm-team/assets/js/12.0bebd69a.js"><link rel="prefetch" href="/jm-team/assets/js/13.ab89afda.js"><link rel="prefetch" href="/jm-team/assets/js/14.cccab28e.js"><link rel="prefetch" href="/jm-team/assets/js/15.811e7806.js"><link rel="prefetch" href="/jm-team/assets/js/16.6b52d65e.js"><link rel="prefetch" href="/jm-team/assets/js/17.2377e7a7.js"><link rel="prefetch" href="/jm-team/assets/js/18.d89e6362.js"><link rel="prefetch" href="/jm-team/assets/js/19.6c8587dd.js"><link rel="prefetch" href="/jm-team/assets/js/2.6f1b5ef5.js"><link rel="prefetch" href="/jm-team/assets/js/20.db588f67.js"><link rel="prefetch" href="/jm-team/assets/js/21.1b6e996b.js"><link rel="prefetch" href="/jm-team/assets/js/22.1efe92bd.js"><link rel="prefetch" href="/jm-team/assets/js/23.27553905.js"><link rel="prefetch" href="/jm-team/assets/js/24.abe75bd5.js"><link rel="prefetch" href="/jm-team/assets/js/25.eedbcfd9.js"><link rel="prefetch" href="/jm-team/assets/js/26.5b1c316e.js"><link rel="prefetch" href="/jm-team/assets/js/27.6d080c8b.js"><link rel="prefetch" href="/jm-team/assets/js/28.4feaaa58.js"><link rel="prefetch" href="/jm-team/assets/js/29.40e0e2d7.js"><link rel="prefetch" href="/jm-team/assets/js/3.92f57443.js"><link rel="prefetch" href="/jm-team/assets/js/30.023098e2.js"><link rel="prefetch" href="/jm-team/assets/js/31.eb0f506d.js"><link rel="prefetch" href="/jm-team/assets/js/32.08513b68.js"><link rel="prefetch" href="/jm-team/assets/js/33.5fb4a125.js"><link rel="prefetch" href="/jm-team/assets/js/34.04ef0c95.js"><link rel="prefetch" href="/jm-team/assets/js/35.ea51e023.js"><link rel="prefetch" href="/jm-team/assets/js/36.41024a3e.js"><link rel="prefetch" href="/jm-team/assets/js/38.34a05ead.js"><link rel="prefetch" href="/jm-team/assets/js/39.29d96e24.js"><link rel="prefetch" href="/jm-team/assets/js/40.5b5ed37f.js"><link rel="prefetch" href="/jm-team/assets/js/41.604c91f9.js"><link rel="prefetch" href="/jm-team/assets/js/42.503a5631.js"><link rel="prefetch" href="/jm-team/assets/js/43.f3b4871c.js"><link rel="prefetch" href="/jm-team/assets/js/44.0b07266d.js"><link rel="prefetch" href="/jm-team/assets/js/7.035493f1.js"><link rel="prefetch" href="/jm-team/assets/js/8.d629a04b.js"><link rel="prefetch" href="/jm-team/assets/js/9.214ade66.js">
    <link rel="stylesheet" href="/jm-team/assets/css/0.styles.e434bceb.css">
  </head>
  <body class="theme-mode-light">
    <div id="app" data-server-rendered="true"><div class="theme-container sidebar-open have-rightmenu"><header class="navbar blur"><div title="目录" class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/jm-team/" class="home-link router-link-active"><img src="/jm-team/img/logo.png" alt="聚名前端团队文档库" class="logo"></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/jm-team/" class="nav-link">首页</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="代码规范" class="dropdown-title"><a href="/jm-team/rule/" class="link-title">代码规范</a> <span class="title" style="display:none;">代码规范</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/jm-team/pages/605eb7/" class="nav-link">常规规范</a></li><li class="dropdown-item"><!----> <a href="/jm-team/pages/c126a2/" class="nav-link">移动端规范</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="组件库" class="dropdown-title"><a href="/jm-team/components/" class="link-title">组件库</a> <span class="title" style="display:none;">组件库</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/jm-team/pages/5e4254/" class="nav-link">传统项目文档</a></li><li class="dropdown-item"><!----> <a href="/jm-team/pages/b295e0/" class="nav-link">Vue项目文档</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="工具库" class="dropdown-title"><a href="/jm-team/util/" class="link-title">工具库</a> <span class="title" style="display:none;">工具库</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/jm-team/pages/06fcb4/" class="nav-link">常用的JS代码</a></li><li class="dropdown-item"><!----> <a href="/jm-team/pages/edd363/" class="nav-link">常用的CSS</a></li><li class="dropdown-item"><!----> <a href="/jm-team/pages/80d4db/" class="nav-link">框架类</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="资源库" class="dropdown-title"><a href="/jm-team/assets/" class="link-title">资源库</a> <span class="title" style="display:none;">资源库</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/jm-team/pages/c9bdd7/" class="nav-link">文档资源</a></li></ul></div></div><div class="nav-item"><a href="/jm-team/newspaper/" class="nav-link">前端小报</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="索引" class="dropdown-title"><a href="/jm-team/archives/" class="link-title">索引</a> <span class="title" style="display:none;">索引</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/jm-team/categories/" class="nav-link">分类</a></li><li class="dropdown-item"><!----> <a href="/jm-team/tags/" class="nav-link">标签</a></li><li class="dropdown-item"><!----> <a href="/jm-team/archives/" class="nav-link">归档</a></li></ul></div></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <div class="sidebar-hover-trigger"></div> <aside class="sidebar" style="display:none;"><!----> <nav class="nav-links"><div class="nav-item"><a href="/jm-team/" class="nav-link">首页</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="代码规范" class="dropdown-title"><a href="/jm-team/rule/" class="link-title">代码规范</a> <span class="title" style="display:none;">代码规范</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/jm-team/pages/605eb7/" class="nav-link">常规规范</a></li><li class="dropdown-item"><!----> <a href="/jm-team/pages/c126a2/" class="nav-link">移动端规范</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="组件库" class="dropdown-title"><a href="/jm-team/components/" class="link-title">组件库</a> <span class="title" style="display:none;">组件库</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/jm-team/pages/5e4254/" class="nav-link">传统项目文档</a></li><li class="dropdown-item"><!----> <a href="/jm-team/pages/b295e0/" class="nav-link">Vue项目文档</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="工具库" class="dropdown-title"><a href="/jm-team/util/" class="link-title">工具库</a> <span class="title" style="display:none;">工具库</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/jm-team/pages/06fcb4/" class="nav-link">常用的JS代码</a></li><li class="dropdown-item"><!----> <a href="/jm-team/pages/edd363/" class="nav-link">常用的CSS</a></li><li class="dropdown-item"><!----> <a href="/jm-team/pages/80d4db/" class="nav-link">框架类</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="资源库" class="dropdown-title"><a href="/jm-team/assets/" class="link-title">资源库</a> <span class="title" style="display:none;">资源库</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/jm-team/pages/c9bdd7/" class="nav-link">文档资源</a></li></ul></div></div><div class="nav-item"><a href="/jm-team/newspaper/" class="nav-link">前端小报</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="索引" class="dropdown-title"><a href="/jm-team/archives/" class="link-title">索引</a> <span class="title" style="display:none;">索引</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/jm-team/categories/" class="nav-link">分类</a></li><li class="dropdown-item"><!----> <a href="/jm-team/tags/" class="nav-link">标签</a></li><li class="dropdown-item"><!----> <a href="/jm-team/archives/" class="nav-link">归档</a></li></ul></div></div> <!----></nav>  <ul class="sidebar-links"><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading open"><span>常规规范</span> <span class="arrow down"></span></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/jm-team/pages/605eb7/" class="sidebar-link">HTML规范</a></li><li><a href="/jm-team/pages/e4e400/" aria-current="page" class="active sidebar-link">CSS规范</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level2"><a href="/jm-team/pages/e4e400/#编码规范" class="sidebar-link">编码规范</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/jm-team/pages/e4e400/#文档内嵌样式表编码" class="sidebar-link">文档内嵌样式表编码</a></li><li class="sidebar-sub-header level3"><a href="/jm-team/pages/e4e400/#文档外链样式表编码" class="sidebar-link">文档外链样式表编码</a></li><li class="sidebar-sub-header level3"><a href="/jm-team/pages/e4e400/#样式表编码" class="sidebar-link">样式表编码</a></li><li class="sidebar-sub-header level3"><a href="/jm-team/pages/e4e400/#团队约定" class="sidebar-link">团队约定</a></li></ul></li><li class="sidebar-sub-header level2"><a href="/jm-team/pages/e4e400/#代码风格" class="sidebar-link">代码风格</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/jm-team/pages/e4e400/#代码格式化" class="sidebar-link">代码格式化</a></li><li class="sidebar-sub-header level3"><a href="/jm-team/pages/e4e400/#代码大小写" class="sidebar-link">代码大小写</a></li><li class="sidebar-sub-header level3"><a href="/jm-team/pages/e4e400/#选择器" class="sidebar-link">选择器</a></li><li class="sidebar-sub-header level3"><a href="/jm-team/pages/e4e400/#代码缩进" class="sidebar-link">代码缩进</a></li><li class="sidebar-sub-header level3"><a href="/jm-team/pages/e4e400/#分号" class="sidebar-link">分号</a></li><li class="sidebar-sub-header level3"><a href="/jm-team/pages/e4e400/#代码易读性" class="sidebar-link">代码易读性</a></li><li class="sidebar-sub-header level3"><a href="/jm-team/pages/e4e400/#属性值引号" class="sidebar-link">属性值引号</a></li><li class="sidebar-sub-header level3"><a href="/jm-team/pages/e4e400/#属性书写顺序" class="sidebar-link">属性书写顺序</a></li><li class="sidebar-sub-header level3"><a href="/jm-team/pages/e4e400/#css3浏览器私有前缀写法" class="sidebar-link">CSS3浏览器私有前缀写法</a></li></ul></li></ul></li><li><a href="/jm-team/pages/8937fa/" class="sidebar-link">JS规范</a></li><li><a href="/jm-team/pages/050126/" class="sidebar-link">命名规范</a></li><li><a href="/jm-team/pages/e161f9/" class="sidebar-link">图片规范</a></li></ul></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>移动端规范</span> <span class="arrow right"></span></p> <!----></section></li></ul> </aside> <div><main class="page"><div class="theme-vdoing-wrapper "><div class="articleInfo-wrap" data-v-06970110><div class="articleInfo" data-v-06970110><ul class="breadcrumbs" data-v-06970110><li data-v-06970110><a href="/jm-team/" title="首页" class="iconfont icon-home router-link-active" data-v-06970110></a></li> <li data-v-06970110><a href="/jm-team/categories/?category=%E8%A7%84%E8%8C%83" title="分类" data-v-06970110>规范</a></li><li data-v-06970110><a href="/jm-team/categories/?category=%E5%B8%B8%E8%A7%84%E8%A7%84%E8%8C%83" title="分类" data-v-06970110>常规规范</a></li></ul> <div class="info" data-v-06970110><div title="作者" class="author iconfont icon-touxiang" data-v-06970110><a href="https://github.com/xugaoyi" target="_blank" title="作者" class="beLink" data-v-06970110>聚名前端</a></div> <div title="创建时间" class="date iconfont icon-riqi" data-v-06970110><a href="javascript:;" data-v-06970110>2022-09-20</a></div> <!----></div></div></div> <!----> <div class="content-wrapper"><div class="right-menu-wrapper"><div class="right-menu-margin"><div class="right-menu-title">目录</div> <div class="right-menu-content"></div></div></div> <h1><img src="">CSS规范<!----></h1> <!----> <div class="theme-vdoing-content content__default"><h2 id="编码规范"><a href="#编码规范" class="header-anchor">#</a> 编码规范</h2> <p>CSS样式表是一个序列通用字符集，传输和存储过程中，这些字符必须由支持 US-ASCII（例如 UTF-8, ISO 8859-x, SHIFT JIS 等）字符编码方式编译</p> <h3 id="文档内嵌样式表编码"><a href="#文档内嵌样式表编码" class="header-anchor">#</a> 文档内嵌样式表编码</h3> <blockquote><p>When a style sheet is embedded in another document, such as in the STYLE element or “style” attribute of HTML, the style sheet shares the character encoding of the whole document.</p></blockquote> <p>当样式出现在其它文档，如 HTML 的 STYLE 标签或标签属性 “style”，样式的编码由文档的决定。</p> <h3 id="文档外链样式表编码"><a href="#文档外链样式表编码" class="header-anchor">#</a> 文档外链样式表编码</h3> <blockquote><p>When a style sheet resides in a separate file, user agents must observe the following priorities when determining a style sheet’s character encoding (from highest priority to lowest):</p></blockquote> <blockquote><ol><li>An HTTP “charset” parameter in a “Content-Type” field (or similar parameters in other protocols)</li> <li>BOM and/or @charset</li> <li>or other metadata from the linking mechanism (if any)
4.charset of referring style sheet or document (if any)
5.Assume UTF-8
文档外链样式表的编码可以由以下各项按照由高到低的优先级顺序决定：</li></ol></blockquote> <ol><li>HTTP “Content-Type” 字段参数 “charset”（或其它协议相似的参数）</li> <li>BOM（byte-order mark）和（或）@charset</li> <li>Link 中的元数据设置（如果有的话）</li> <li>引用样式表字符集或文档编码（如果有的话）</li> <li>假定为 UTF-8 编码</li></ol> <h3 id="样式表编码"><a href="#样式表编码" class="header-anchor">#</a> 样式表编码</h3> <blockquote><p>Authors using an @charset rule must place the rule at the very beginning of the style sheet, preceded by no characters. (If a byte order mark is appropriate for the encoding used, it may precede the @charset rule.)</p></blockquote> <blockquote><p>@charset must be written literally, i.e., the 10 characters ‘@charset “‘ (lowercase, no backslash escapes), followed by the encoding name, followed by ‘“;’.</p></blockquote> <ul><li>@charset规则一定要在样式文件的第一行首个字符位置开始，否则的话就会有机会让 BOM 设置生效（如果有设置 BOM 的话）而优于 @charset 作为样式表的编码</li> <li>@charset &quot;&quot;; 一定要写上，并且用小写字母，不能出现转义符</li></ul> <h3 id="团队约定"><a href="#团队约定" class="header-anchor">#</a> 团队约定</h3> <ul><li>样式文件必须写上 @charset 规则，并且一定要在样式文件的第一行首个字符位置开始写，编码名用 “UTF-8”</li> <li>字符 @charset “”; 都用小写字母，不能出现转义符，编码名允许大小混写</li> <li>考虑到在使用“UTF-8”编码情况下 BOM 对代码的污染和编码显示的问题，在可控范围下，坚决不使用 BOM。（更多关于 BOM 可参考 BOM的介绍 和 「带 BOM 的 UTF-8」和「无 BOM 的 UTF-8」有什么区别？ ）</li></ul> <p><em>推荐：</em></p> <div class="language-css line-numbers-mode"><pre class="language-css"><code><span class="token atrule"><span class="token rule">@charset</span> <span class="token string">&quot;UTF-8&quot;</span><span class="token punctuation">;</span></span>

<span class="token selector">.jdc</span><span class="token punctuation">{</span><span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p><em>不推荐：</em></p> <div class="language-css line-numbers-mode"><pre class="language-css"><code><span class="token comment">/**
 * @desc File Info
 * @author Author Name
 * @date 2015-10-10
 */</span>
 
<span class="token comment">/* @charset规则不在文件首行首个字符开始 */</span>
<span class="token atrule"><span class="token rule">@charset</span> <span class="token string">&quot;UTF-8&quot;</span><span class="token punctuation">;</span></span>

<span class="token selector">.jdc</span><span class="token punctuation">{</span><span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br></div></div><div class="language-css line-numbers-mode"><pre class="language-css"><code><span class="token atrule"><span class="token rule">@CHARSET</span> <span class="token string">&quot;UTF-8&quot;</span><span class="token punctuation">;</span></span>
<span class="token comment">/* @charset规则没有用小写 */</span>

<span class="token selector">.jdc</span><span class="token punctuation">{</span><span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><div class="language-css line-numbers-mode"><pre class="language-css"><code><span class="token comment">/* 无@charset规则 */</span>
<span class="token selector">.jdc</span><span class="token punctuation">{</span><span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p>更多关于样式编码：<a href="http://www.w3.org/TR/2011/REC-CSS2-20110607/syndata.html#charset" target="_blank" rel="noopener noreferrer">CSS style sheet representation<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></p> <h2 id="代码风格"><a href="#代码风格" class="header-anchor">#</a> 代码风格</h2> <h3 id="代码格式化"><a href="#代码格式化" class="header-anchor">#</a> 代码格式化</h3> <p>样式书写一般有两种：一种是紧凑格式 (Compact)</p> <div class="language-css line-numbers-mode"><pre class="language-css"><code><span class="token selector">.jdc</span><span class="token punctuation">{</span> <span class="token property">display</span><span class="token punctuation">:</span> block<span class="token punctuation">;</span><span class="token property">width</span><span class="token punctuation">:</span> 50px<span class="token punctuation">;</span><span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>一种是展开格式（Expanded）</p> <div class="language-css line-numbers-mode"><pre class="language-css"><code><span class="token selector">.jdc</span><span class="token punctuation">{</span>
    <span class="token property">display</span><span class="token punctuation">:</span> block<span class="token punctuation">;</span>
    <span class="token property">width</span><span class="token punctuation">:</span> 50px<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><p><strong>团队约定</strong></p> <p>统一使用展开格式书写样式</p> <h3 id="代码大小写"><a href="#代码大小写" class="header-anchor">#</a> 代码大小写</h3> <p>样式选择器，属性名，属性值关键字全部使用小写字母书写，属性字符串允许使用大小写。</p> <div class="language-css line-numbers-mode"><pre class="language-css"><code><span class="token comment">/* 推荐 */</span>
<span class="token selector">.jdc</span><span class="token punctuation">{</span>
	<span class="token property">display</span><span class="token punctuation">:</span>block<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
	
<span class="token comment">/* 不推荐 */</span>
<span class="token selector">.JDC</span><span class="token punctuation">{</span>
	<span class="token property">DISPLAY</span><span class="token punctuation">:</span>BLOCK<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><h3 id="选择器"><a href="#选择器" class="header-anchor">#</a> 选择器</h3> <ul><li>尽量少用通用选择器 *</li> <li>不使用 ID 选择器</li> <li>不使用无具体语义定义的标签选择器</li></ul> <div class="language-css line-numbers-mode"><pre class="language-css"><code><span class="token comment">/* 推荐 */</span>
<span class="token selector">.jdc</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
<span class="token selector">.jdc li</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
<span class="token selector">.jdc li p</span><span class="token punctuation">{</span><span class="token punctuation">}</span>

<span class="token comment">/* 不推荐 */</span>
<span class="token selector">*</span><span class="token punctuation">{</span><span class="token punctuation">}</span>
<span class="token selector">#jdc</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
<span class="token selector">.jdc div</span><span class="token punctuation">{</span><span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><h3 id="代码缩进"><a href="#代码缩进" class="header-anchor">#</a> 代码缩进</h3> <p>统一使用四个空格进行代码缩进，使得各编辑器表现一致（各编辑器有相关配置）</p> <div class="language-css line-numbers-mode"><pre class="language-css"><code><span class="token selector">.jdc</span> <span class="token punctuation">{</span>
    <span class="token property">width</span><span class="token punctuation">:</span> 100%<span class="token punctuation">;</span>
    <span class="token property">height</span><span class="token punctuation">:</span> 100%<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><h3 id="分号"><a href="#分号" class="header-anchor">#</a> 分号</h3> <p>每个属性声明末尾都要加分号；</p> <div class="language-css line-numbers-mode"><pre class="language-css"><code><span class="token selector">.jdc</span> <span class="token punctuation">{</span>
    <span class="token property">width</span><span class="token punctuation">:</span> 100%<span class="token punctuation">;</span>
    <span class="token property">height</span><span class="token punctuation">:</span> 100%<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><h3 id="代码易读性"><a href="#代码易读性" class="header-anchor">#</a> 代码易读性</h3> <p>左括号与类名之间一个空格，冒号与属性值之间一个空格</p> <p><em>推荐：</em></p> <div class="language-css line-numbers-mode"><pre class="language-css"><code><span class="token selector">.jdc</span> <span class="token punctuation">{</span> 
    <span class="token property">width</span><span class="token punctuation">:</span> 100%<span class="token punctuation">;</span> 
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p><em>不推荐：</em></p> <div class="language-css line-numbers-mode"><pre class="language-css"><code><span class="token selector">.jdc</span><span class="token punctuation">{</span> 
    <span class="token property">width</span><span class="token punctuation">:</span>100%<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p>逗号分隔的取值，逗号之后一个空格</p> <p><em>推荐：</em></p> <div class="language-css line-numbers-mode"><pre class="language-css"><code><span class="token selector">.jdc</span> <span class="token punctuation">{</span>
    <span class="token property">box-shadow</span><span class="token punctuation">:</span> 1px 1px 1px #333<span class="token punctuation">,</span> 2px 2px 2px #ccc<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p><em>不推荐：</em></p> <div class="language-css line-numbers-mode"><pre class="language-css"><code><span class="token selector">.jdc</span> <span class="token punctuation">{</span>
    <span class="token property">box-shadow</span><span class="token punctuation">:</span> 1px 1px 1px #333<span class="token punctuation">,</span>2px 2px 2px #ccc<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p>为单个css选择器或新申明开启新行</p> <p><em>推荐：</em></p> <div class="language-css line-numbers-mode"><pre class="language-css"><code><span class="token selector">.jdc, 
.jdc_logo, 
.jdc_hd</span> <span class="token punctuation">{</span>
    <span class="token property">color</span><span class="token punctuation">:</span> #ff0<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token selector">.nav</span><span class="token punctuation">{</span>
    <span class="token property">color</span><span class="token punctuation">:</span> #fff<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br></div></div><p><em>不推荐：</em></p> <div class="language-css line-numbers-mode"><pre class="language-css"><code><span class="token selector">.jdc,jdc_logo,.jdc_hd</span> <span class="token punctuation">{</span>
    <span class="token property">color</span><span class="token punctuation">:</span> #ff0<span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token selector">.nav</span><span class="token punctuation">{</span>
    <span class="token property">color</span><span class="token punctuation">:</span> #fff<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><p>颜色值 <code>rgb()</code> <code>rgba()</code> <code>hsl()</code> <code>hsla()</code> <code>rect()</code> 中不需有空格，且取值不要带有不必要的 0</p> <p><em>推荐：</em></p> <div class="language-css line-numbers-mode"><pre class="language-css"><code><span class="token selector">.jdc</span> <span class="token punctuation">{</span>
    <span class="token property">color</span><span class="token punctuation">:</span> <span class="token function">rgba</span><span class="token punctuation">(</span>255<span class="token punctuation">,</span>255<span class="token punctuation">,</span>255<span class="token punctuation">,</span>.5<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p><em>不推荐：</em></p> <div class="language-css line-numbers-mode"><pre class="language-css"><code><span class="token selector">.jdc</span> <span class="token punctuation">{</span>
    <span class="token property">color</span><span class="token punctuation">:</span> <span class="token function">rgba</span><span class="token punctuation">(</span> 255<span class="token punctuation">,</span> 255<span class="token punctuation">,</span> 255<span class="token punctuation">,</span> 0.5 <span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p>属性值十六进制数值能用简写的尽量用简写</p> <p><em>推荐：</em></p> <div class="language-css line-numbers-mode"><pre class="language-css"><code><span class="token selector">.jdc</span> <span class="token punctuation">{</span>
    <span class="token property">color</span><span class="token punctuation">:</span> #fff<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p><em>不推荐：</em></p> <div class="language-css line-numbers-mode"><pre class="language-css"><code><span class="token selector">.jdc</span> <span class="token punctuation">{</span>
    <span class="token property">color</span><span class="token punctuation">:</span> #ffffff<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p>不要为 0 指明单位</p> <p><em>推荐：</em></p> <div class="language-css line-numbers-mode"><pre class="language-css"><code><span class="token selector">.jdc</span> <span class="token punctuation">{</span>
    <span class="token property">margin</span><span class="token punctuation">:</span> 0 10px<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p><em>不推荐：</em></p> <div class="language-css line-numbers-mode"><pre class="language-css"><code><span class="token selector">.jdc</span> <span class="token punctuation">{</span>
    <span class="token property">margin</span><span class="token punctuation">:</span> 0px 10px<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><h3 id="属性值引号"><a href="#属性值引号" class="header-anchor">#</a> 属性值引号</h3> <p>css属性值需要用到引号时，统一使用单引号</p> <div class="language-css line-numbers-mode"><pre class="language-css"><code><span class="token comment">/* 推荐 */</span>
<span class="token selector">.jdc</span> <span class="token punctuation">{</span> 
	<span class="token property">font-family</span><span class="token punctuation">:</span> <span class="token string">'Hiragino Sans GB'</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token comment">/* 不推荐 */</span>
<span class="token selector">.jdc</span> <span class="token punctuation">{</span> 
	<span class="token property">font-family</span><span class="token punctuation">:</span> <span class="token string">&quot;Hiragino Sans GB&quot;</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><h3 id="属性书写顺序"><a href="#属性书写顺序" class="header-anchor">#</a> 属性书写顺序</h3> <p>建议遵循以下顺序：</p> <ol><li>布局定位属性：display / position / float / clear / visibility / overflow</li> <li>自身属性：width / height / margin / padding / border / background</li> <li>文本属性：color / font / text-decoration / text-align / vertical-align / white- space / break-word</li> <li>其他属性（CSS3）：content / cursor / border-radius / box-shadow / text-shadow / background:linear-gradient …</li></ol> <div class="language-css line-numbers-mode"><pre class="language-css"><code><span class="token selector">.jdc</span> <span class="token punctuation">{</span>
    <span class="token property">display</span><span class="token punctuation">:</span> block<span class="token punctuation">;</span>
    <span class="token property">position</span><span class="token punctuation">:</span> relative<span class="token punctuation">;</span>
    <span class="token property">float</span><span class="token punctuation">:</span> left<span class="token punctuation">;</span>
    <span class="token property">width</span><span class="token punctuation">:</span> 100px<span class="token punctuation">;</span>
    <span class="token property">height</span><span class="token punctuation">:</span> 100px<span class="token punctuation">;</span>
    <span class="token property">margin</span><span class="token punctuation">:</span> 0 10px<span class="token punctuation">;</span>
    <span class="token property">padding</span><span class="token punctuation">:</span> 20px 0<span class="token punctuation">;</span>
    <span class="token property">font-family</span><span class="token punctuation">:</span> Arial<span class="token punctuation">,</span> <span class="token string">'Helvetica Neue'</span><span class="token punctuation">,</span> Helvetica<span class="token punctuation">,</span> sans-serif<span class="token punctuation">;</span>
    <span class="token property">color</span><span class="token punctuation">:</span> #333<span class="token punctuation">;</span>
    <span class="token property">background</span><span class="token punctuation">:</span> <span class="token function">rgba</span><span class="token punctuation">(</span>0<span class="token punctuation">,</span>0<span class="token punctuation">,</span>0<span class="token punctuation">,</span>.5<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token property">-webkit-border-radius</span><span class="token punctuation">:</span> 10px<span class="token punctuation">;</span>
    <span class="token property">-moz-border-radius</span><span class="token punctuation">:</span> 10px<span class="token punctuation">;</span>
    <span class="token property">-o-border-radius</span><span class="token punctuation">:</span> 10px<span class="token punctuation">;</span>
    <span class="token property">-ms-border-radius</span><span class="token punctuation">:</span> 10px<span class="token punctuation">;</span>
    <span class="token property">border-radius</span><span class="token punctuation">:</span> 10px<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br></div></div><p><a href="https://www.mozilla.org/css/base/content.css" target="_blank" rel="noopener noreferrer">mozilla官方属性顺序推荐<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></p> <h3 id="css3浏览器私有前缀写法"><a href="#css3浏览器私有前缀写法" class="header-anchor">#</a> CSS3浏览器私有前缀写法</h3> <p>CSS3 浏览器私有前缀在前，标准前缀在后</p> <div class="language-css line-numbers-mode"><pre class="language-css"><code><span class="token selector">.jdc</span> <span class="token punctuation">{</span>
    <span class="token property">-webkit-border-radius</span><span class="token punctuation">:</span> 10px<span class="token punctuation">;</span>
    <span class="token property">-moz-border-radius</span><span class="token punctuation">:</span> 10px<span class="token punctuation">;</span>
    <span class="token property">-o-border-radius</span><span class="token punctuation">:</span> 10px<span class="token punctuation">;</span>
    <span class="token property">-ms-border-radius</span><span class="token punctuation">:</span> 10px<span class="token punctuation">;</span>
    <span class="token property">border-radius</span><span class="token punctuation">:</span> 10px<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><p>更多关于浏览器私有前辍写法：<a href="http://www.w3.org/TR/2011/REC-CSS2-20110607/syndata.html#vendor-keywords" target="_blank" rel="noopener noreferrer">#Vendor-specific extensions<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></p></div></div> <!----> <div class="page-edit"><!----> <!----> <div class="last-updated"><span class="prefix">上次更新:</span> <span class="time">2022/11/09, 01:52:48</span></div></div> <div class="page-nav-wapper"><div class="page-nav-centre-wrap"><a href="/jm-team/pages/605eb7/" class="page-nav-centre page-nav-centre-prev"><div class="tooltip">HTML规范</div></a> <a href="/jm-team/pages/8937fa/" class="page-nav-centre page-nav-centre-next"><div class="tooltip">JS规范</div></a></div> <div class="page-nav"><p class="inner"><span class="prev">
        ←
        <a href="/jm-team/pages/605eb7/" class="prev">HTML规范</a></span> <span class="next"><a href="/jm-team/pages/8937fa/">JS规范</a>→
      </span></p></div></div></div> <div class="article-list"><div class="article-title"><a href="/jm-team/archives/" class="iconfont icon-bi">最近更新</a></div> <div class="article-wrapper"><dl><dd>01</dd> <dt><a href="/jm-team/pages/ee1a90/"><div>
            uniapp学习指南
            <!----></div></a> <span class="date">11-09</span></dt></dl><dl><dd>02</dd> <dt><a href="/jm-team/pages/a46909/"><div>
            JS常用工具函数封装
            <!----></div></a> <span class="date">09-30</span></dt></dl><dl><dd>03</dd> <dt><a href="/jm-team/pages/64dca1/"><div>
            Nuxt爬坑指南
            <!----></div></a> <span class="date">09-30</span></dt></dl> <dl><dd></dd> <dt><a href="/jm-team/archives/" class="more">更多文章&gt;</a></dt></dl></div></div></main></div> <div class="footer"><!----> 
  Theme by
  <a href="https://github.com/xugaoyi/vuepress-theme-vdoing" target="_blank" title="本站主题">Vdoing</a> 
    | Copyright © 2022-2022
    <span>聚名前端 | <a href="https://github.com/xugaoyi/vuepress-theme-vdoing/blob/master/LICENSE" target="_blank">MIT License</a></span></div> <div class="buttons"><div title="返回顶部" class="button blur go-to-top iconfont icon-fanhuidingbu" style="display:none;"></div> <div title="去评论" class="button blur go-to-comment iconfont icon-pinglun" style="display:none;"></div></div> <!----> <!----> <!----></div><div class="global-ui"></div></div>
    <script src="/jm-team/assets/js/app.99b82987.js" defer></script><script src="/jm-team/assets/js/5.d18fc731.js" defer></script><script src="/jm-team/assets/js/6.c8a66f32.js" defer></script><script src="/jm-team/assets/js/37.c0a8f76a.js" defer></script>
  </body>
</html>
